﻿using System;
using System.IO;
using System.Reflection;

namespace TeF.Runner.Services
{
    internal class TestAssemblyLoader : ITestAssemblyLoader
    {
        public Assembly Load(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
                throw new ArgumentException("path");

            if (Path.GetExtension(path) != ".dll")
                throw new TestAssemblyLoaderException(
                    "Assembly must have 'dll' extension. Path to assembly is '{0}'.", path);

            if (!File.Exists(path))
                throw new TestAssemblyLoaderException(
                    "Cannot find assembly on path '{0}'.", path);

            return Assembly.LoadFrom(path);
        }
    }
}
